/**
 * 商户项目管理页面js
 * 版权所有：上海戈品投资管理有限公司
 *   author king
     功能说明：商户项目管理页面
     创建日期：2015-09-28
     修改记录：
     备注说明：
 */


var mid;

$(document).ready(function() {
	
	mid = $('#mid').val();
	if( mid )//区别是从菜单进入还是从商户管理页面进入的
	{
		$('.backToMerchantManage').show();
	}	
	else
	{
		$('.query_condition input').val('');
		$('.query_condition').show();
	}	
	merchantProjectList();
	
	var json = common.ajaxRequest('service', {"p":"merchantManage","m":"redpackSummary"}, 'GET');
	if( json && json.result == 0 )
	{
		$('.redpack_lastNo').text( json.summary.lastNo);
		$('.redpack_usedNo').text( json.summary.usedNo);
		$('.redpack_summary').show();
		$('.exchangeCode_summary .total').text(json.exchangeCodeSummary);
		$('.exchangeCode_summary').show();
	}

});

window.onload=function(){
	
	 $(".newProPopTime .input-group.date").datepicker({
	        todayBtn: "linked",
	        keyboardNavigation: false,
	        forceParse: false,
	        calendarWeeks: true,
	        autoclose: true
	    });
};
/**
 * 返回商户管理列表
 * @returns
 */
var backToMerchantManage = function(){
	window.location.href='page?p=page/merchantList';
};

/**
 * 过滤数据
 * @returns
 */
var filterData = function(obj){
	var value = $(obj).val();
	
	if( value )
	{
		$('.card').hide();
		var cardList = $('.card');
		$(cardList).each(function(){
			var id = $(this).attr('id');
			if( id.indexOf( value ) >= 0 )
			{
				$(this).show();
			}	
		});
	}
	else
	{
		$('.card').show();
	}	
};



/**
 * 查询商户项目列表
 * @returns
 */
var merchantProjectList = function(){
	
	var projectName = $('.query_condition .projectName').val();
	var datas = {"p":"merchantManage","m":"findProjectList","wxName":projectName};//请求参数
	
	if( mid!='' &&mid > 0 )
	{
		datas =  {"p":"merchantManage","m":"findProjectList","mid":mid};
	}	
	
	var columnDefine = {};//表格栏目定义
	var formatters = {//自定义表格格式
            "startTime": function (column, row)
            {
            	var date = new Date( row.startTime );
            	return date.getFullYear()+'-' + (date.getMonth()+1)+ '-' + date.getDate();
            },
			"endTime": function (column, row)
			{
				var date = new Date( row.startTime );
				return date.getFullYear()+'-' + (date.getMonth()+1)+ '-' + date.getDate();
			}
	};
	
	var buttons =''; //操作按钮
	buttons+='<p>';
	//buttons+='<button type=\'button\' class=\'btn btn-w-m btn-primary\' onclick="">操作1</button>';
	buttons+='</p>';
	//hui.pager('service',datas ,"merchantProjectList", columnDefine , formatters , buttons ); //分页查询
	
	var json = common.ajaxRequest('service', datas, 'GET');
	
	if( json && json.result == 0 )
	{
		var html = '';
		var link ='';
		
		$('.query_condition .label-info').text(json.merchantList.length);
		
		$(json.merchantList).each(function(){
			
			
			var avalibleMoney = parseFloat(this.summaryMoney).toFixed(2) - parseFloat(this.totalMoney).toFixed(2);
			
			var rate = (1 - this.totalMoney/(this.summaryMoney==0?1:this.summaryMoney))*100;
			rate = parseFloat(rate).toFixed(2);
			
			//alert(parseFloat(this.summaryMoney).toFixed(2) );
			
			var serviceType = '';
			
			if( this.wxServiceType == 1 )
			{
				serviceType = '订阅号';
			}
			if( this.wxServiceType == 2 )
			{
				serviceType = '服务号';
			}
			if( this.wxServiceType == 3 )
			{
				serviceType = 'APP';
			}
			if( this.wxServiceType == 4 )
			{
				serviceType = '个人号';
			}
			if( this.wxServiceType == 5 )
			{
				serviceType = '网站';
			}
			
			
			html+='<div class="col-sm-4  card" id="'+this.wx_name+'"  onclick="showPopMenu(this);">';
                    
			      if( this.summaryMoney == 0 ) //黄色异常警告
			      {
			    	  html+='<div class="contact-box" style="background-color:#ffffcc">';
			      }  
			      else if( this.summaryMoney>0 && rate >=90 ) //红色预警
				  {
					  html+='<div class="contact-box" style="background-color:#ff3366">';
				  }	
				  else
				  {
					  html+='<div class="contact-box">';
				  }  
					html+='<a href="javascript:void(0);">';
						    html+='<div class="col-sm-4">';
								html+='<div class="text-center">';
								if( this.type == 1 )
								{
									html+='<img class="img-circle m-t-xs img-responsive" src="images/tuo.png" alt="托管" onclick="showTestLink('+this.id+');"><br>';
									html+='<p style="font-weight:bold;font-size:18px;margin-right:52px;">' + serviceType + '</p>';
									html+='<p style="font-weight:bold;font-size:14px;margin-right:52px;color:'+(this.isAuthority == 1?'red':'green')+'">' 
										    + (this.isAuthority == 1?'未认证':'已认证') + '</p>';
								}
								else if( this.type == 2 ) 
								{
									html+='<img class="img-circle m-t-xs img-responsive" src="images/jiekou.png" alt="接口"><br>';
									html+='<p style="font-weight:bold;font-size:18px;margin-right:52px;">' + serviceType + '</p>';
									html+='<p style="font-weight:bold;font-size:14px;margin-right:52px;color:'+(this.isAuthority == 1?'red':'green')+'">' 
								    + (this.isAuthority == 1?'未认证':'已认证') + '</p>';
								}	
								else if( this.type == 3 && this.interfaceType == 3  ) 
								{
									html+='<img class="img-circle m-t-xs img-responsive" src="images/question.png" alt="回答问题领红包"><br>';
									html+='<p style="font-weight:bold;font-size:18px;margin-right:52px;">' + serviceType + '</p>';
									html+='<p style="font-weight:bold;font-size:14px;margin-right:52px;color:'+(this.isAuthority == 1?'red':'green')+'">' 
									+ (this.isAuthority == 1?'未认证':'已认证') + '</p>';
								}	
								else
								{
									html+='<img class="img-circle m-t-xs img-responsive" src="images/qi.png" alt="其它"><br>';
									html+='<p style="font-weight:bold;font-size:18px;margin-right:52px;">'  + '</p>';
								}	
								html+='</div>';
							html+='</div>';
							html+='<div class="col-sm-8">';
							html+='<h3>';
							html+='<strong>'+this.wx_name+'</strong>&nbsp;&nbsp;&nbsp;';
							//html+= this.type==2?'<button class="btn btn-outline btn-info" type="button">接口</button>':'<button class="btn btn-outline btn-danger" type="button">托管</button>';
							html+='</h3>';
							html+='<p>推荐人数:' + this.usedNo + '</p>';
							html+='<p>可用余额:' + parseFloat(this.totalMoney).toFixed(2)+ '</p>';
							html+='<p>已消费金额:' + parseFloat(avalibleMoney).toFixed(2)+ '</p>';
							html+='<p>总金额:' + parseFloat(this.summaryMoney).toFixed(2)+ '</p>';
							html+='<p>兑换码:' + (this.unUsedNo+this.usedNo)+'/'+this.unUsedNo+ '</p>';
							html+='<p>从' + parseDate( this.startTime ) +' 到 ' + parseDate( this.endTime ) + '</p>';
							
							link ='page?p=page/projectSummary&id='+this.id+"&totalMoney="+this.totalMoney+'&summaryMoney='+this.summaryMoney+
					         '&startTime=' +parseDate( this.startTime ) +'&endTime=' + parseDate( this.endTime )+'&wxName=' + this.wx_name +
					         '&usedNo=' + this.usedNo+'&unUsedNo=' + this.unUsedNo + '&type='+this.type ;
							
							html+='<p style="display:none" class="popbuttons">';
							   html+='<button class=\"btn btn-outline btn-success dim\" type=\"button\" onclick="$(\'#pop_menu\').modal(\'hide\');showModifyWin('+this.id+');"><i class=\"fa fa-edit\">&nbsp;编辑</i></button>';
							   html+='<button class=\"btn btn-outline btn-success dim\" type=\"button\" onclick="$(\'#pop_menu\').modal(\'hide\');window.location.href=\''+link+'\'"><i class=\"fa fa-cog\">&nbsp;详情</i></button>';
							   html+='<button class=\"btn btn-outline btn-success dim\" type=\"button\" onclick="$(\'#pop_menu\').modal(\'hide\');showSetupGroupWin('+this.id+');"><i class=\"fa fa-group\">&nbsp;分组</i></button>';
							   html+='<button class=\"btn btn-outline btn-success dim\" type=\"button\" onclick="$(\'#pop_menu\').modal(\'hide\');showFillInWin('+this.id+');"><i class=\"fa fa-yen\">&nbsp;充值</i></button>';
							   html+='<button class=\"btn btn-outline btn-success dim\" type=\"button\" onclick="$(\'#pop_menu\').modal(\'hide\');showEditPageHtml('+this.id+');"><i class=\"fa fa-pagelines\">&nbsp;页面</i></button>';
							   html+='<button class=\"btn btn-outline btn-success dim\" type=\"button\" onclick="$(\'#pop_menu\').modal(\'hide\');exportProjectUserData('+this.id+');"><i class=\"fa fa-file-excel-o\">&nbsp;导出</i></button>';
							   html+='<button class=\"btn btn-outline btn-success dim\" type=\"button\" onclick="$(\'#pop_menu\').modal(\'hide\');showQuestionList('+this.id+');"><i class=\"fa fa-stack-exchange\">&nbsp;问题</i></button>';
							html+='</p>';
							
/*							html+='<p style="display:none" class="popbuttons"><button type=\'button\' class=\'btn btn-sm btn-info\' style="margin-top:10px;" onclick="showModifyWin('+this.id+');">编辑</button>&nbsp;&nbsp;';
							link ='page?p=page/projectSummary&id='+this.id+"&totalMoney="+this.totalMoney+'&summaryMoney='+this.summaryMoney+
							         '&startTime=' +parseDate( this.startTime ) +'&endTime=' + parseDate( this.endTime )+'&wxName=' + this.wx_name +
							         '&usedNo=' + this.usedNo+'&unUsedNo=' + this.unUsedNo + '&type='+this.type ;
							html+='<button type=\'button\' class=\'btn btn-sm btn-success\' style="margin-top:10px;" onclick="window.location.href=\''+link+'\'">详情</button>&nbsp;&nbsp;';
							html+='<button type=\'button\' class=\'btn btn-sm btn-danger\' style="margin-top:10px;" onclick="showSetupGroupWin('+this.id+');">设置分组</button>&nbsp;&nbsp;';
							html+='<button type=\'button\' class=\'btn btn-sm btn-primary\' style="margin-top:10px;" onclick="showFillInWin('+this.id+');">充值</button>&nbsp;&nbsp;';
							html+='<button type=\'button\' class=\'btn btn-sm btn-info\' style="margin-top:10px;" onclick="showQuestionList('+this.id+');">查看问题</button>&nbsp;&nbsp;';
							html+='<button type=\'button\' class=\'btn btn-sm btn-info\' style="margin-top:10px;" onclick="showEditPageHtml('+this.id+');">编辑页面</button>&nbsp;&nbsp;';
							html+='<button type=\'button\' class=\'btn btn-sm btn-warning\' style="margin-top:10px;" onclick="exportProjectUserData('+this.id+');">导出数据</button></p>';*/
							html+='<p>';
							html+='<div class="stat-percent">'+rate+'%</div>';
							html+='<div class="progress progress-mini">';
								html+='<div class="progress-bar" style="width: '+rate+'%;"></div>';
							html+='</div>';
						html+='</p>';
						html+='</div>';
						html+='<div class="clearfix"></div>';
					html+=' </a>';
				html+='</div>';
			html+='</div>';
			
			
		});
		$('#boxViewList').empty();
		$('#boxViewList').append(html);
        $('.contact-box').each(function () {
            animationHover(this, 'pulse');
        });
	}	
	
};

/**
 * 显示弹出窗口
 * @param obj
 * @returns
 */
var showPopMenu = function( obj )
{
	var html = $(obj).find('.popbuttons').html();
	$('#pop_menu .modal-body').empty();
	$('#pop_menu .modal-body').append(html);
	$('#pop_menu').modal('show');
	
};

/**
 * 显示调试链接
 * @param pid
 * @returns
 */
var showTestLink = function(pid){
	
	var json = common.ajaxRequest('jsp/config.jsp', {}, 'GET');
	if( json && json.result == 0 )
	{
		var url = json.url;
		url =url.substring(0,url.lastIndexOf("/"));
		url = url.substring(url.indexOf(".")+1);
		alert( "http://"+ url + '/wxOther/index.php?pid='+pid);
	}	
	
};

/**
 * 打开新建窗口
 * @returns
 */
var showNewWin = function(){
	
	$('#newMerchantProjectPop input').val('');
	
	var json = common.ajaxRequest('service', {"p":"merchantManage","m":"findMerchantList" } , 'GET');
	if( json && json.result == 0 )
	{
		$('#newMerchantProjectPop .mid').empty();
		$(json.merchantList).each(function(){
			
			$('#newMerchantProjectPop .mid').append('<option value="'+this.id+'">'+this.name+'</option>');
		});
	}
	
	$('#newMerchantProjectPop').modal('show');
};

/**
 * 打开编辑窗口
 * @returns
 */
var showModifyWin = function( id){
	
	$('#modifyMerchantProjectPop input').val('');
	$('#modifyMerchantProjectPop img').attr('src','');
	$('#modifyMerchantProjectPop .fa-chevron-up').removeClass('fa-chevron-up').addClass('fa-chevron-down');
	$('#modifyMerchantProjectPop .ibox-content').hide();
	
	if( id > 0  )
	{
		var json = common.ajaxRequest('service', {"p":"merchantManage","m":"findMerchantList" } , 'GET');
		if( json && json.result == 0 )
		{
			$('#modifyMerchantProjectPop .mid').empty();
			$(json.merchantList).each(function(){
				
				$('#modifyMerchantProjectPop .mid').append('<option value="'+this.id+'">'+this.name+'</option>');
			});
		}
		
		json = common.ajaxRequest('service?p=merchantManage&m=findProjectById&id='+id, {}, 'GET');
		if( json && json.result == 0 )
		{
			var m = json.project;
			
			
			
			$('#modifyMerchantProjectPop .id').val( m.id );
			$('#modifyMerchantProjectPop .projectNo').val( m.projectNo );
			$('#modifyMerchantProjectPop .mid').val( m.mid );
			$('#modifyMerchantProjectPop .totalMoney').val( m.totalMoney );
			$('#modifyMerchantProjectPop .summaryMoney').val( m.summaryMoney );
			$('#modifyMerchantProjectPop .operatorMoney').val( m.operatorMoney );
			$('#modifyMerchantProjectPop .agentMoney').val( m.agentMoney );
			$('#modifyMerchantProjectPop .isOpen').val( m.isOpen );
			$('#modifyMerchantProjectPop .startTime').val( parseDate(m.startTime) );
			$('#modifyMerchantProjectPop .endTime').val( parseDate(m.endTime) );
			$('#modifyMerchantProjectPop .wxName').val( m.wx_name );
			$('#modifyMerchantProjectPop .wxAppId').val( m.wx_appId );
			$('#modifyMerchantProjectPop .wxSecret').val( m.wx_secret );
			$('#modifyMerchantProjectPop .wxToken').val( m.wx_token );
			$('#modifyMerchantProjectPop .wxUrl').val( m.wx_url );
			$('#modifyMerchantProjectPop .price').val( m.price );
			$('#modifyMerchantProjectPop .description').val( m.description);
			$('#modifyMerchantProjectPop .logoUrl ').val( m.logoUrl );
			$('#modifyMerchantProjectPop .projectUrl').val( m.projectUrl);
			$('#modifyMerchantProjectPop .interfaceType').val( m.interfaceType);
			$('#modifyMerchantProjectPop .interfaceUrl').val( m.interfaceUrl);
			$('#modifyMerchantProjectPop .verifyType').val( m.verifyType);
			$('#modifyMerchantProjectPop .interfaceKey').val( m.interfaceKey);
			$('#modifyMerchantProjectPop .activeUrl').val( m.activeUrl);
			$('#modifyMerchantProjectPop .isFaceScan').val( m.isFaceScan);
			$('#modifyMerchantProjectPop .isSpread').val( m.isSpread);
			$('#modifyMerchantProjectPop .nameListType').val( m.nameListType);
			$('#modifyMerchantProjectPop .isNeedHead').val( m.isNeedHead);
			if(m.interfaceType>0 )
			{
				//$('#modifyMerchantProjectPop .interfaceUrl').parent().parent().show();
				selectInterfaceType($('#modifyMerchantProjectPop .interfaceType'));
			}	
			
			$('#modifyMerchantProjectPop .accessToken').val( m.accessToken);
			$('#modifyMerchantProjectPop .autoReply').val( m.autoReply);
			$('#modifyMerchantProjectPop .accessTokenTime').val( m.accessTokenTime);
			$('#modifyMerchantProjectPop .currentMoney').val( m.currentMoney);
			$('#modifyMerchantProjectPop .wxServiceType').val( m.wxServiceType);
			$('#modifyMerchantProjectPop .isAuthority').val( m.isAuthority);
			$('#modifyMerchantProjectPop .indexNo').val( m.indexNo);
			
			$('#modifyMerchantProjectPop .province').val(m.province);
			$('#modifyMerchantProjectPop .city').val(m.city);
			$('#modifyMerchantProjectPop .district').val(m.district);
			$('#modifyMerchantProjectPop .cityCode').val(m.cityCode);
			
			if( null!=m.logoUrl && m.logoUrl !='' )
			{
				$('#modifyMerchantProjectPop .logoUrlImage').attr('src', m.logoUrl);
				$('#modifyMerchantProjectPop .logoUrlImage').show();
			}
			else
			{
				$('#modifyMerchantProjectPop .logoUrlImage').hide();
			}
			
			if( null!=m.banner && m.banner !='' )
			{
				$('#ed_bannerUrl').parent().find('img').attr('src', m.banner).show();
				$('#ed_bannerUrl').parent().find('.banner').val(m.banner);
			}
			else
			{
				$('#ed_bannerUrl').parent().find('img').hide();
			}	
			
			if( m.wxServiceType == 2 && m.isAuthority == 2 ) //认证 的服务号
			{
				$('#codePicUrl1').show();
				$('#codePicUrl2').hide();
			}
			else //接口
			{
				$('#codePicUrl1').hide();
				$('#codePicUrl2').show();
			}	
			
			$('#modifyMerchantProjectPop').modal('show');
			
			if( m.codePicUrl )
			{
				//$('#modifyMerchantProjectPop .codePicUrlImage').remove();
				$('#codePicUrl2').parent().find('img').attr('src',m.codePicUrl);
				$('#codePicUrl2').parent().find('.codePicUrl').val(m.codePicUrl);
			}
			else
			{
				//$('#modifyMerchantProjectPop .codePicUrlImage').remove();
				$('#codePicUrl2').parent().find('.codePicUrl').val('');
			}	
		}
		else
		{
			common.showMsg('error', '' , '查询出错!');
		}	
		
	}	
	else
	{
		common.showMsg('error', '' , '请选择要编辑的商户!');
	}	
	
};

/**
 * 判断显示是否展示生成二维码按钮
 * @returns
 */
var showCreateCodeLink = function(){
	
	var wxServiceType = $('#modifyMerchantProjectPop .wxServiceType').val();
	var isAuthority = $('#modifyMerchantProjectPop .isAuthority').val();
	
	if( wxServiceType == 2 && isAuthority == 2 ) //认证 的服务号
	{
		$('#codePicUrl1').show();
		$('#codePicUrl2').hide();
	}
	else //接口
	{
		$('#codePicUrl1').hide();
		$('#codePicUrl2').show();
	}	
};

/**
 * 新建项目
 * @returns
 */
var newMerchantProject = function(){

	/* 校验表单*/
	if(!validator.validate('#newMerchantProjectPop'))
	{
		return;
	}	
	
	var mid = $('#newMerchantProjectPop .mid').val();
	var totalMoney = $('#newMerchantProjectPop .totalMoney').val();
	var price = $('#newMerchantProjectPop .price').val();
	var operatorMoney = $('#newMerchantProjectPop .operatorMoney').val();
	var agentMoney = $('#newMerchantProjectPop .agentMoney').val();
	var isOpen = $('#newMerchantProjectPop .isOpen').val();
	var startTime = $('#newMerchantProjectPop .startTime').val();
	var endTime = $('#newMerchantProjectPop .endTime').val();
	var wxName = $('#newMerchantProjectPop .wxName').val();
	var wxAppId = $('#newMerchantProjectPop .wxAppId').val();
	var wxSecret = $('#newMerchantProjectPop .wxSecret').val();
	var wxToken = $('#newMerchantProjectPop .wxToken').val();
	var wxUrl = $('#newMerchantProjectPop .wxUrl').val();
	var projectUrl = $('#newMerchantProjectPop .projectUrl').val();
	var logoUrl = $('#newMerchantProjectPop .logoUrl').val();
	var description = $('#newMerchantProjectPop .description').val();
	var interfaceType = $('#newMerchantProjectPop .interfaceType').val();
	var interfaceUrl = $('#newMerchantProjectPop .interfaceUrl').val();
	var autoReply = $('#newMerchantProjectPop .autoReply').val();
	var accessToken = $('#newMerchantProjectPop .accessToken').val();
	var accessTokenTime = $('#newMerchantProjectPop .accessTokenTime').val();
	var wxServiceType = $('#newMerchantProjectPop .wxServiceType').val();
	var isAuthority = $('#newMerchantProjectPop .isAuthority').val();
	var indexNo = $('#newMerchantProjectPop .indexNo').val();
	var verifyType = $('#newMerchantProjectPop .verifyType').val();
	var interfaceKey = $('#newMerchantProjectPop .interfaceKey').val();
	var isFaceScan = $('#newMerchantProjectPop .isFaceScan').val();
	var isSpread = $('#newMerchantProjectPop .isSpread').val();
	var nameListType = $('#newMerchantProjectPop .nameListType').val();
	var isNeedHead = $('#newMerchantProjectPop .isNeedHead').val();
	
	var province  = $('#newMerchantProjectPop .province').val();
	var city  = $('#newMerchantProjectPop .city').val();
	var district  = $('#newMerchantProjectPop .district').val();
	var cityCode  = $('#newMerchantProjectPop .cityCode').val();
	var banner  = $('#newMerchantProjectPop .banner').val();
	var activeUrl  = $('#newMerchantProjectPop .activeUrl').val();
	
	var params = 'p=merchantManage&m=addProject&mid='+mid+'&totalMoney='+totalMoney+'&price=' + price +'&projectUrl='+projectUrl +'&logoUrl='+logoUrl+
	                      '&operatorMoney='+operatorMoney+'&agentMoney='+agentMoney+'&isOpen='+isOpen+'&startTime='+startTime+'&endTime='+endTime+'&isNeedHead='+isNeedHead+
	                      '&wxName='+wxName+'&wxAppId='+wxAppId+'&wxSecret='+wxSecret+'&wxToken='+wxToken+'&wxUrl='+wxUrl+'&description='+description+
	                      '&interfaceType='+interfaceType+'&interfaceUrl='+interfaceUrl+'&accessToken='+accessToken+'&autoReply='+autoReply+'&interfaceKey='+interfaceKey+
	                      '&wxServiceType='+wxServiceType+'&isAuthority='+isAuthority+'&indexNo='+indexNo+'&verifyType='+verifyType+'&province='+province+ '&nameListType='+nameListType+
	                      '&isFaceScan='+isFaceScan+'&isSpread='+isSpread+'&city='+city+'&district='+district+'&cityCode='+cityCode+'&banner='+banner +'&activeUrl='+activeUrl;
	
	var json = common.ajaxRequest('service?'+params, null, 'GET');
	if( json && json.result == 0 )
	{
		common.showMsg('info', '创建成功', '创建成功');
		merchantProjectList();
		$('#newMerchantProjectPop').modal('hide');
	}
	else
	{
		common.showMsg('error', '创建失败', json.message);
	}	
};

/**
 * 编辑项目
 * @returns
 */
var modifyMerchantProject = function(){
	
	/* 校验表单*/
	if(!validator.validate('#modifyMerchantProjectPop'))
	{
		return;
	}	
	
	var id = $('#modifyMerchantProjectPop .id').val();
	var mid = $('#modifyMerchantProjectPop .mid').val();
	//var totalMoney = $('#modifyMerchantProjectPop .totalMoney').val();
	//var summaryMoney = $('#modifyMerchantProjectPop .summaryMoney').val();
	var operatorMoney = $('#modifyMerchantProjectPop .operatorMoney').val();
	var agentMoney = $('#modifyMerchantProjectPop .agentMoney').val();
	var isOpen = $('#modifyMerchantProjectPop .isOpen').val();
	var startTime = $('#modifyMerchantProjectPop .startTime').val();
	var endTime = $('#modifyMerchantProjectPop .endTime').val();
	var wxName = $('#modifyMerchantProjectPop .wxName').val();
	var wxAppId = $('#modifyMerchantProjectPop .wxAppId').val();
	var wxSecret = $('#modifyMerchantProjectPop .wxSecret').val();
	var wxToken = $('#modifyMerchantProjectPop .wxToken').val();
	var wxUrl = $('#modifyMerchantProjectPop .wxUrl').val();
	var codePicUrl = $('#modifyMerchantProjectPop .codePicUrl').val();
	var description = $('#modifyMerchantProjectPop .description').val();
	var projectUrl = $('#modifyMerchantProjectPop .projectUrl').val();
	var logoUrl = $('#modifyMerchantProjectPop .logoUrl').val();
	var interfaceType = $('#modifyMerchantProjectPop .interfaceType').val();
	var interfaceUrl = $('#modifyMerchantProjectPop .interfaceUrl').val();
	var autoReply = $('#modifyMerchantProjectPop .autoReply').val();
	var interfaceKey = $('#modifyMerchantProjectPop .interfaceKey').val();
	var isFaceScan = $('#modifyMerchantProjectPop .isFaceScan').val();
	var isSpread = $('#modifyMerchantProjectPop .isSpread').val();
	var nameListType = $('#modifyMerchantProjectPop .nameListType').val();
	var isNeedHead = $('#modifyMerchantProjectPop .isNeedHead').val();
	
	var accessToken = $('#modifyMerchantProjectPop .accessToken').val();
	var accessTokenTime = $('#modifyMerchantProjectPop .accessTokenTime').val();
	var wxServiceType = $('#modifyMerchantProjectPop .wxServiceType').val();
	var isAuthority = $('#modifyMerchantProjectPop .isAuthority').val();
	var currentMoney = $('#modifyMerchantProjectPop .currentMoney').val();
	var indexNo = $('#modifyMerchantProjectPop .indexNo').val();
	var verifyType = $('#modifyMerchantProjectPop .verifyType').val();
	
	var province  = $('#modifyMerchantProjectPop .province').val();
	var city  = $('#modifyMerchantProjectPop .city').val();
	var district  = $('#modifyMerchantProjectPop .district').val();
	var cityCode  = $('#modifyMerchantProjectPop .cityCode').val();
	var banner  = $('#modifyMerchantProjectPop .banner').val();
	var activeUrl  = $('#modifyMerchantProjectPop .activeUrl').val();
	
	var params = 'p=merchantManage&m=modifyProject&mid='+mid+'&operatorMoney='+operatorMoney+'&agentMoney='+agentMoney+'&projectUrl='+projectUrl+
	                       '&isOpen='+isOpen+'&startTime='+startTime+'&endTime='+endTime+ '&wxName='+wxName+'&wxAppId='+wxAppId+'&logoUrl='+logoUrl+'&isNeedHead='+isNeedHead+
	                       '&wxSecret='+wxSecret+'&wxToken='+wxToken+'&wxUrl='+wxUrl+'&description='+description +'&id='+id+'&codePicUrl='+codePicUrl+'&nameListType='+nameListType+
		                   '&interfaceType='+interfaceType+'&interfaceUrl='+interfaceUrl+'&accessToken='+accessToken+"&autoReply="+autoReply+'&interfaceKey='+interfaceKey+
		                   '&wxServiceType='+wxServiceType+'&isAuthority='+isAuthority+'&currentMoney='+currentMoney+'&indexNo='+indexNo+'&verifyType='+verifyType+
		                   '&isFaceScan='+isFaceScan+'&isSpread='+isSpread+'&province='+province+'&city='+city+'&district='+district+'&cityCode='+cityCode+'&banner='+banner+'&activeUrl='+activeUrl;
	
	var json = common.ajaxRequest('service?'+params, null, 'GET');
	if( json && json.result == 0 )
	{
		common.showMsg('info', '修改成功', '修改成功');
		merchantProjectList();
		$('#modifyMerchantProjectPop').modal('hide');
	}
	else
	{
		common.showMsg('error', '修改失败', json.message);
	}	
};

var parseDate = function( value ){
	var date = new Date( value );
	return date.getFullYear()+'-' + (date.getMonth()+1)+ '-' + date.getDate();
};

/**
 * 上传二维码图片
 * @returns
 */
var uploadImage = function( id,type ){
	
    $.ajaxFileUpload({
        url: 'jsp/upload.jsp?type='+type, 
        type: 'post',
        secureuri: false, //一般设置为false
        fileElementId: id, // 上传文件的id、name属性名
        dataType: 'json', //返回值类型，一般设置为json、application/json
        success: function(data, status){  
        	//alert(JSON.stringify(data));
        	if( data && data.result == 0 )
        	{
        		$('#'+id).parent().find('.codePicUrl').val(data.imageUrl);
        		$('#'+id).parent().find('.codePicUrlImage').attr('src',data.imageUrl).show();
        	}	
        },
        error: function(data, status, e){ 
        	common.showMsg('error', null , '上传失败');
        }
    });
};

/**
 * 上传项目logo图片
 * @returns
 */
var uploadLogoImage = function( id ){
	
	$.ajaxFileUpload({
		url: 'jsp/upload.jsp', 
		type: 'post',
		secureuri: false, //一般设置为false
		fileElementId: id, // 上传文件的id、name属性名
		dataType: 'json', //返回值类型，一般设置为json、application/json
		success: function(data, status){  
			if( data && data.result == 0 )
			{
				$('#'+id).parent().find('.image').val(data.imageUrl);
				$('#'+id).parent().find('.logoUrlImage').attr('src',data.imageUrl).show();
			}	
		},
		error: function(data, status, e){ 
			common.showMsg('error', null , '上传失败');
		}
	});
};

/**
 * 显示充值窗口
 * @returns
 */
var showFillInWin = function(id){
	$('#projectFillIn .id').val(id);
	$('#projectFillIn .money').val('');
	$('#projectFillIn .price').val('');
	$('#projectFillIn .remark').val('');
	$('#projectFillIn').modal('show');
};

/**
 * 项目充值
 * @returns
 */
var projectFillIn = function(){
	
	
	/* 校验表单*/
	if(!validator.validate('#projectFillIn'))
	{
		return;
	}	
	var money = $('#projectFillIn .money').val();
	var price = $('#projectFillIn .price').val();
	var id = $('#projectFillIn .id').val();
	var remark = $('#projectFillIn .remark').val();
	var json = common.ajaxRequest('service', {"p":"merchantManage","m":"fillIn","id":id,"money":money,"price":price,"remark":remark}, 'POST');
	if( json && json.result == 0 )
	{
		merchantProjectList();
		$('#projectFillIn').modal('hide');
		common.showMsg('info', '' , '充值成功!' );
	}
	else
	{
		common.showMsg('error', '' ,  json.message );
	}	
};

/**
 * 调用接口生成二维码
 * @param obj
 * @returns
 */
var createCode = function(){
	
	var id = $('#modifyMerchantProjectPop .id').val();
	var json = common.ajaxRequest('service?p=merchantManage&m=createCode&id='+id, null , 'GET');
	if( json && json.result == 0 )
	{
		$('#modifyMerchantProjectPop .codePicUrl').val(json.returnJson.codePicUrl);
		$('#modifyMerchantProjectPop .codePicUrlImage').attr('src',json.returnJson.codePicUrl).show();
	}
	else
	{
		common.showMsg('error', '' ,  json.message );
	}	
};

/**
 * 调用接口生成二维码
 * @param obj
 * @returns
 */
var exportCode = function( id ){
	
	if( id && id > 0 )
	{
		var json = common.ajaxRequest('service?p=merchantManage&m=exportCode&id='+id , null , 'GET');
		if( json && json.result == 0 )
		{
			window.open(json.excelFile);
		}
		else
		{
			common.showMsg('error', '' ,  json.message );
		}	
	}
	else
	{
		common.showMsg('error', '' , '选择要导出的项目');
	}	

};

/**
 * 选择接口类型，显示接口地址编辑框
 * @returns
 */
var selectInterfaceType = function( obj ){
	
	var value = $(obj).val();
	if( value > 0 )
	{
		$(obj).parent().parent().parent().find('.interfaceUrl0').show();
		$(obj).parent().parent().parent().find('.interfaceKey0').show();
	}
	else
	{
		$(obj).parent().parent().parent().find('.interfaceUrl0').hide();
		$(obj).parent().parent().parent().find('.interfaceKey0').hide();
	}	
};

/**
 * 显示项目宣传页面编辑窗口
 * @param id
 * @returns
 */
var showEditPageHtml = function( id ){
	
	$('#modifyProjectPageHtmlWin .ibox').empty();
	$('#modifyProjectPageHtmlWin .ibox').append('	<div class="pageHtml"></div>');
	var json = common.ajaxRequest('service', {"p":"merchantManage","m":"findProjectPageHtml","id":id}, 'POST');
	if( json && json.result == 0 )
	{
		$('#modifyProjectPageHtmlWin .id').val(id);
		$('#modifyProjectPageHtmlWin .pageHtml').html( json.pageHtml);
		$('#modifyProjectPageHtmlWin .pageTitle').val( json.pageTitle);
	    $(".pageHtml").summernote({
	        lang: "zh-CN"
	    });
		$('#modifyProjectPageHtmlWin').modal('show');
	}
	else
	{
		common.showMsg('error', '', '查询失败!');
		return;
	}	
};

/**
 * 修改项目宣传页面
 * @returns
 */
var modifyProjectPageHtml = function(){
	
	var id = $('#modifyProjectPageHtmlWin .id').val();
    var pageHtml = $('#modifyProjectPageHtmlWin .note-editable').html();
    var pageTitle = $('#modifyProjectPageHtmlWin .pageTitle').val();
	//var json = common.ajaxRequest('service', {"p":"merchantManage","m":"modifyProjectPageHtml","id":id,"pageHtml":pageHtml}, 'POST');
	//var json = common.ajaxRequest('jsp/request.jsp', {"id":id,"pageHtml":pageHtml}, 'POST');
	//window.location.href='http://localhost:8080/wx/ajax?p=merchantManage&m=modifyProjectPageHtml&id='+id+'&pageHtml='+pageHtml;
    var json =  common.ajaxRequest('jsp/config.jsp', {}, 'GET');
    if( json && json.result == 0 )
    {
    	//window.open('?p=merchantManage&m=modifyProjectPageHtml&mobile=true&id='+id+'&pageHtml='+pageHtml);
    	$('#id').val(id);
    	$('#pageHtml').val(pageHtml);
    	$('#pageTitle').val(pageTitle);
    	$('#modifyProject').attr('action',json.url);
    	$('#modifyProject').submit();
    	//$('#modifyProjectPageHtmlWin').modal('hide');
    }
    else
    {
		common.showMsg('error', '', '编辑失败!');
		return;
    }	
    
    

/*	if( json && json.result == 0 )
	{
		$('#modifyProjectPageHtmlWin').modal('hide');
		common.showMsg('info', '', '编辑成功!');
	}
	else
	{
		common.showMsg('error', '', '编辑失败!');
		return;
	}*/
};

/**
 * 导出项目关注人详情excel数据
 * @returns
 */
var exportProjectUserData = function( projectId ){
	
	var json = common.ajaxRequest('service', {"p":"merchantManage","m":"exportProjectUserData","projectId":projectId}, 'POST');
	if( json && json.result == 0 )
	{
		window.open( json.excelFile );
	}
	else
	{
		common.showMsg('error', '', json.message);
		return;
	}	
};

/**
 * 显示设置分组窗口
 * @returns
 */
var showSetupGroupWin = function(id){
	

	var json = common.ajaxRequest('service', {"p":"groupManage","m":"findProjectGroupList","projectId":id}, 'POST');
	var html='';
	if( json && json.groupProjectList )
	{
		$( json.groupProjectList).each(function(){
			if( this.flag > 0 )
			{
				html+='<input type="checkbox" name="type0" value="'+this.id+'" checked="checked">'+this.name+'<br>';
			}
			else
			{
				html+='<input type="checkbox" name="type0" value="'+this.id+'">'+this.name+'<br>';
			}	
		});
	}
	$('#editProjectGroupPop .projectId').val(id);
	$('#editProjectGroupPop .selectList').empty();
	$('#editProjectGroupPop .selectList').html(html);
	$('#editProjectGroupPop').modal('show');
};

/**
 * 设置分组
 * @returns
 */
var setupGroup = function(){
	var projectId = $('#editProjectGroupPop .projectId').val();
	var groupIds ='';
	$('input[name="type0"]:checked').each(function(){
		groupIds+= $(this).val()+ ',';
	});
	groupIds = groupIds.substring(0, groupIds.lastIndexOf(','));
	if( groupIds == null || groupIds == '' || groupIds == undefined )
	{
		common.showMsg('error', '' , '请选择要设置的分组');
		return;
	}	
	var datas = {"p":"groupManage","m":"addGroupProject","projectId":projectId,"groupIds":groupIds};
	var json = common.ajaxRequest('service', datas , 'POST');
	if( json && json.result == 0 )
	{
		$('#editProjectGroupPop').modal('hide');
		common.showMsg('info', '' , '设置分组成功');
	}
	else
	{
		common.showMsg('error', '' , '设置分组失败');
		return;
	}	
};

/**
 * 显示问题列表
 * @returns
 */
var showQuestionList = function( id ){
	window.location.href='page?p=page/questionManage&projectId='+id;
};


